import 'package:flutter/material.dart';
import 'package:leader_help/utils/component/component.dart';
import 'package:leader_help/utils/component/empty.dart';
import 'package:leader_help/utils/util.dart';
import 'package:get/get.dart';

import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'controller.dart';
import 'views/cell.dart';

class MsgPage extends StatelessWidget {
  MsgPage({Key? key}) : super(key: key);
  final controller = Get.put(MsgController());
  @override
  Widget build(BuildContext context) {
    return GetBuilder<MsgController>(builder: (_) {
      return Scaffold(
        backgroundColor: ColorsUtil.white,
        appBar: AppBar(
          title: Text(
            '消息',
            style: pfSCStyle(color: ColorsUtil.title, fontSize: 18.sp),
          ),
        ),
        body: SmartRefresher(
          controller: controller.state.refreshCtrl,
          onRefresh: controller.onRefresh,
          onLoading: controller.onLoading,
          enablePullUp: true,
          child: controller.state.dataSource.isEmpty
              ? EmptyView()
              : ListView.separated(
                  itemBuilder: (context, index) {
                    return MsgCell(md: controller.state.dataSource[index]);
                  },
                  separatorBuilder: (context, index) => Container(
                        margin: EdgeInsets.symmetric(horizontal: gap12),
                        height: 1.r,
                        color: ColorsUtil.separator,
                      ),
                  itemCount: controller.state.dataSource.length),
        ),
      );
    });
  }
}
